package LeetcodeTest_twelve;
//单值二叉树

import java.util.Scanner;

public class isUnivalTree
{
    public static void main(String[] args)
    {
        TreeNode root=null;
        root=Solution.createTree(root);
        System.out.println(Solution.isUnivalTree(root));
    }
}

class Solution {
    public static boolean isUnivalTree(TreeNode root)
    {
        return  traverse(root.val,root);
    }
    public static boolean traverse(int a,TreeNode T)
    {
        if(T!=null)
        {
            return a==T.val&&traverse(a,T.left)&&traverse(a,T.right);
        }
        else
            return true;
    }
    public static TreeNode createTree(TreeNode T)
    {
        Scanner reader=new Scanner(System.in);
        int a=reader.nextInt();
        TreeNode p=null;
        if (a==-1)
            p=null;
        else
            p = new TreeNode(a);
        T=p;
        if(T==null)
            return T;
        else
        {
            T.left = createTree(T.left);
            T.right = createTree(T.right);
        }
        return T;
    }
}
class TreeNode
{
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode(int x) { val = x; }
}